package com.yzc.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.yzc.mapper.MessageCountMapper;
import com.yzc.model.entity.notification.MessageCount;
import com.yzc.model.entity.notification.MessageDto;
import com.yzc.model.entity.notification.Notification;
import com.yzc.service.NotificationService;
import com.yzc.mapper.NotificationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Yzc
 * @description 针对表【t_notification】的数据库操作Service实现
 * @createDate 2024-10-23 09:10:46
 */
@Service
public class NotificationServiceImpl extends ServiceImpl<NotificationMapper, Notification>
        implements NotificationService {

    @Autowired
    private NotificationMapper notificationMapper;
    @Autowired
    private MessageCountMapper messageCountMapper;


    @Override
    public List<MessageCount> selectByacceptuserid(Integer acceptuserid) {
        return messageCountMapper.selectByacceptuserid(acceptuserid);
    }

    @Override
    public List<Notification> selectBySenduserid(Integer senduserid, Integer acceptuserid) {
        return notificationMapper.selectBySenduserid(senduserid, acceptuserid);
    }

    @Override
    public void updateState(Integer senduserid, Integer acceptuserid) {
        notificationMapper.updateById(senduserid, acceptuserid);
    }

    @Override
    public void sendBysenduserid(Integer senduserid, Integer acceptuserid, String content) {
        notificationMapper.updatesendBysenduserid(senduserid, acceptuserid, content);

    }

    @Override
    public void sendGroupMessage(List<MessageDto> messageDtos) {
        for (MessageDto message : messageDtos) {
            // 这里可以调用 MyBatis Mapper 方法来保存消息
            notificationMapper.sendGroupMessage(message);
            System.out.println("Received message from " + message.getSenduserid() +
                    " to " + message.getAcceptuserid() +
                    ": " + message.getContent());
        }
    }

    @Override
    public List<Notification> sendGroupMessageByacceptuserid(Integer acceptuserid) {

        return notificationMapper.sendGroupMessageByacceptuserid(acceptuserid);
    }


}




